package com.xinlong.shop.core.temp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinlong.shop.core.temp.entity.BuyGroup;
import com.xinlong.shop.core.temp.mapper.BuyGroupMapper;
import com.xinlong.shop.core.temp.service.IBuyGroupService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 抢购老系统临时使用 服务实现类
 * </p>
 *
 * @author Sylow
 * @since 2023-04-07
 */
@Service
public class BuyGroupServiceImpl extends ServiceImpl<BuyGroupMapper, BuyGroup> implements IBuyGroupService {

    @Override
    public void update(BuyGroup buyGroup, Integer id) {
        UpdateWrapper<BuyGroup> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        this.update(buyGroup, updateWrapper);
    }
    @Override
    public void delete(Integer id) {
        UpdateWrapper<BuyGroup> deleteWrapper = new UpdateWrapper<>();
        deleteWrapper.eq("id", id);
        this.remove(deleteWrapper);
    }

    @Override
    public BuyGroup find(String ruleId, Integer goodsId, Integer productId) {
        QueryWrapper<BuyGroup> query  = new QueryWrapper<>();
        query.eq("rule_id", ruleId);
        query.eq("goods_id", goodsId);
        query.eq("product_id", productId);
        BuyGroup buyGroup = this.getOne(query);
        return buyGroup;
    }

    @Override
    public List<BuyGroup> findList(String ruleId, Integer memberId) {
        QueryWrapper<BuyGroup> query  = new QueryWrapper<>();
        query.eq("rule_id", ruleId);
        query.eq("member_id", memberId);
        return this.list(query);
    }

    @Override
    public void delete(Integer memberId, String ruleId, Integer goodsId) {
        UpdateWrapper<BuyGroup> deleteWrapper = new UpdateWrapper<>();
        deleteWrapper.eq("rule_id", ruleId);
        deleteWrapper.eq("goods_id", goodsId);
        deleteWrapper.eq("member_id", memberId);
        this.remove(deleteWrapper);
    }

    @Override
    public void batchDelete(Integer memberId) {
        UpdateWrapper<BuyGroup> deleteWrapper = new UpdateWrapper<>();
        deleteWrapper.eq("member_id", memberId);
        this.remove(deleteWrapper);
    }

}
